<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Tablebuilder {

   
	var $ci;
	var $query;
	function __construct()
    {
        $this->ci =& get_instance();
       
    }
	public function test()
	{
	
	}
    public function set_query($sql)
    {
    	$this->query = $this->ci->db->query($sql);
    }
   
    function get_table()
    {
    	$data["fields"] = $this->query->list_fields();
    	$data["rows"] = $this->query->result_array();

    	return $this->ci->load->view("report_builder/table",$data,true);
    }
    function get_xml()
    {
    	
    	$this->ci->load->dbutil();


		$config = array (
                  'root'    => 'root',
                  'element' => 'element',
                  'newline' => "\n",
                  'tab'    => "\t"
                );
	
	 return $this->ci->dbutil->xml_from_result($this->query, $config); 
    }
    function get_csv()
    {
    	$this->ci->load->dbutil();
    	$delimiter = ",";
		$newline = "\r\n";

		 echo $this->ci->dbutil->csv_from_result($query, $delimiter, $newline); 
	    }
    
	
}